
/*
饿汉模式
 */
class Singelhunger {
    //保证单例
    private static Singelhunger singelhunger= new Singelhunger();
    //其他类只可通过get方法获取SingelLine的实例
    public Singelhunger getSingelhunger(){
        return singelhunger;
    }
    //将构造方法设置为私有，即可限制其他类无法创建该类的实例
    private Singelhunger(){}
}
/*
懒汉模式
 */
class Singellazy{
    private static Singellazy singellazy = null;
    private Singellazy(){}
    public Singellazy getSingellazy(){
        //判断是否需要加锁  如果没有这层则该线程性能将会很低
        if(singellazy == null){
            synchronized (Singellazy.class){
                //判断是否需要创建对象
                if(singellazy == null){
                    singellazy = new Singellazy();
                }
            }
        }
        return singellazy;
    }
}

public class Singel{
    public static void main(String[] args) {

    }
}
